Skip to content

fix(export): images missing in exported Knowledge Base PDF#28

Merged
Rom1-B merged 3 commits intopluginsGLPI:mainfrom
MyvTsv:ticket37471
May 21, 2025
Merged

fix(export): images missing in exported Knowledge Base PDF#28
Rom1-B merged 3 commits intopluginsGLPI:mainfrom
MyvTsv:ticket37471

Conversation

@MyvTsv
Copy link

@MyvTsv MyvTsv commented Apr 24, 2025

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !37471
  • Knowledge base article images were not exported to PDF

Screenshots (if appropriate):

Capture d’écran du 2025-04-24 16-51-44

Capture d’écran du 2025-04-24 16-54-44

Capture d’écran du 2025-04-24 16-52-20

@MyvTsv MyvTsv requested review from Rom1-B and stonebuzz April 24, 2025 15:03
@MyvTsv MyvTsv self-assigned this Apr 24, 2025
Copy link

@stonebuzz stonebuzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, waiting for customers feedback

@MyvTsv MyvTsv requested a review from stonebuzz April 25, 2025 12:00
Comment on lines 88 to 94
$width = null;

$path = '<img src="file://' . GLPI_DOC_DIR . '/' . $docimg->fields['filepath'] . '"/>';
if (preg_match('/\bwidth=["\']?(\d+)/i', $img[0], $match_width)) {
$width = $match_width[1];
}

$path = '<img src="file://' . GLPI_DOC_DIR . '/' . $docimg->fields['filepath'] . '" width="' . $width . '"/>';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should take the example of the plugin's ticket.class.php class (which also processes images in the content)

 $content = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($job->fields['content']));

        $content = preg_replace('#data:image/[^;]+;base64,#', '@', $content);

        preg_match_all('/<img [^>]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $content, $res, PREG_SET_ORDER);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I took the code from ticket.class.php for image processing. This fixes the problem that prevented the plugin from displaying images but if the image had been resized, it was not taken into account.

@MyvTsv
Copy link
Author

MyvTsv commented May 21, 2025

It's good for customer

@stonebuzz stonebuzz self-requested a review May 21, 2025 13:27
@Rom1-B Rom1-B merged commit 78e7b0d into pluginsGLPI:main May 21, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants